#!/usr/bin/python
#  coding:utf-8
#  -*- coding:utf-8 -*-
import win32api
import win32gui
import win32con
from win32gui import *
import time
import win32clipboard as wc

#
# classname = r"MozillaWindowClass"
# titlename = r"百度一下，你就知道 - Mozilla Firefox"

# def all_ok(hwnd):
#     show_window_attr(hwnd)
#     print hwnd
# print '\xd5\xd2\xb2\xbb\xb5\xbd\xd6\xb8\xb6\xa8\xb5\xc4\xc4\xa3\xbf\xe9\xa1\xa3'.decode('GBK')

def fuc2():
    print 666
def get_child_windows(parent2):
    if not parent2:
        return
    hWndChildList = []
    print parent2
    win32gui.EnumChildWindows(parent2, fuc2, None)
    print 6666666666

def foo(hwnd,mouse):
    #去掉下面这句就所有都输出了，但是我不需要那么多
    if IsWindow(hwnd) and IsWindowEnabled(hwnd) and IsWindowVisible(hwnd):
        hhh = GetWindowText(hwnd)
        aaa = u'微信'
        print hhh.decode('GBK')
        # if False:
        if aaa == hhh.decode('GBK'):
            win = win32gui.FindWindow(None, u'微信')
            # className = win32gui.GetClassName(hwnd)
            print win
            # pwin = FindWindowEx(win, None, 'Edit', None)
            print hwnd

            # win32api.SetCursorPos([300, 300])
            # win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0)
            # time.sleep(0.05)
            # win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0)
            # win32gui.GetWindowRect(win)
            #
            # win32gui.MoveWindow(hwnd, 1500, 50, 300, 200, True)

            # win32gui.SendMessage(pwin, win32con.WM_SETTEXT, None, "66666")

            # print GetDlgItem(hwnd, 1421).encode('GBK')

            # dlg2 = win32gui.FindWindowEx(hwnd, dlg1, 'TrayNotifyWnd', None)
            # win32gui.SendMessage(dlg2, win32con.WM_SETTEXT, None, "66666")

            # dlg3 = win32gui.FindWindowEx(hwnd, dlg2, 'TrayNotifyWnd', None)
            # win32gui.SendMessage(dlg3, win32con.WM_SETTEXT, None, "66666")

            left, top, right, bottom = win32gui.GetWindowRect(hwnd)
            print top,'=',bottom
            print left, '=', right
            print hwnd
            # get_child_windows(hwnd)


# EnumWindows(foo, 0)
# foo(66438,0)hWndList = []
hWndList = []
win32gui.EnumWindows(lambda hwnd, param: param.append(hwnd), hWndList)
for item in hWndList:
    foo(item, 0)
# import time

# while 1:
#     wc.OpenClipboard()
#     copy = wc.GetClipboardData(win32con.CF_TEXT)
#
#     if copy==1:
#         break
#     wc.SetClipboardData(win32con.CF_TEXT,'')
#     wc.CloseClipboard()
#     time.sleep(4)
# print hWndList
